/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.sorbonne.inf1.tp3.model.remote.application;

import fr.sorbonne.inf1.tp3.model.InterfaceApplication;
import exceptions.*;

import fr.sorbonne.inf1.tp3.model.exception.InternalErrorException;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import tp1rmi.RemotePret;

/**
 *
 * @author O.Riad
 */
public class ApplicationRemote implements InterfaceApplication {

    private String remoteObject;

    public ApplicationRemote(String remoteObject) {
        /*try {
        Properties prop;
        prop = new Properties();
        FileInputStream in = new FileInputStream("model.properties");
        prop.load(in);
        this.remoteObject = prop.getProperty("remoteObject");
        in.close();
        } catch (IOException e) {
        System.err.println("Fichier Properties manquants exit");
        System.exit(0);
        }*/
        this.remoteObject = remoteObject;
    }

    @Override
    public Double calculerAnnuite(Double pMontant, int pNb_annee, Double pTaux) throws InternalErrorException, fr.sorbonne.inf1.tp3.model.exception.AnnuiteApplicationException, fr.sorbonne.inf1.tp3.model.exception.MontantApplicationException, fr.sorbonne.inf1.tp3.model.exception.TauxApplicationException, fr.sorbonne.inf1.tp3.model.exception.NbAnneesApplicationException, fr.sorbonne.inf1.tp3.model.exception.CalculAnnuiteApplicationException {
        RemotePret obj = null;
        Double result = 0.0;
        try {
            obj = (RemotePret) Naming.lookup(this.remoteObject);

            result = obj.getAnnuite(pMontant, pNb_annee, pTaux);


        } catch (AnnuiteApplicationException ex) {
            throw new fr.sorbonne.inf1.tp3.model.exception.AnnuiteApplicationException();
        } catch (MontantApplicationException ex) {
            throw new fr.sorbonne.inf1.tp3.model.exception.MontantApplicationException();
        } catch (TauxApplicationException ex) {
            throw new fr.sorbonne.inf1.tp3.model.exception.TauxApplicationException();
        } catch (NbAnneesApplicationException ex) {
            throw new fr.sorbonne.inf1.tp3.model.exception.NbAnneesApplicationException();
        } catch (NotBoundException ex) {
            throw new InternalErrorException();
        } catch (MalformedURLException ex) {
            throw new InternalErrorException();
        } catch (RemoteException e) {
            throw new InternalErrorException();
        }
        return result;
    }

    @Override
    public Double calculerNbAnnees(Double pMontant, Double pTaux, int pAnnuite) throws InternalErrorException, fr.sorbonne.inf1.tp3.model.exception.AnnuiteApplicationException, fr.sorbonne.inf1.tp3.model.exception.MontantApplicationException, fr.sorbonne.inf1.tp3.model.exception.TauxApplicationException, fr.sorbonne.inf1.tp3.model.exception.NbAnneesApplicationException, fr.sorbonne.inf1.tp3.model.exception.CalculAnnuiteApplicationException {
        RemotePret obj = null;
        Double result = 0.0;
        try {
            obj = (RemotePret) Naming.lookup(this.remoteObject);

            result = obj.getNbAnnees(pAnnuite, pMontant, pTaux);


        } catch (CalculAnnuiteApplicationException ex) {
            throw new fr.sorbonne.inf1.tp3.model.exception.CalculAnnuiteApplicationException();
        } catch (AnnuiteApplicationException ex) {
            throw new fr.sorbonne.inf1.tp3.model.exception.AnnuiteApplicationException();
        } catch (MontantApplicationException ex) {
            throw new fr.sorbonne.inf1.tp3.model.exception.MontantApplicationException();
        } catch (TauxApplicationException ex) {
            throw new fr.sorbonne.inf1.tp3.model.exception.TauxApplicationException();
        } catch (NbAnneesApplicationException ex) {
            throw new fr.sorbonne.inf1.tp3.model.exception.NbAnneesApplicationException();
        } catch (NotBoundException ex) {
            throw new InternalErrorException();
        } catch (MalformedURLException ex) {
            throw new InternalErrorException();
        } catch (RemoteException e) {
            throw new InternalErrorException();
        }
        return result;
    }
}
